package com.chixing.ih.module.programmer.controller;

import com.chixing.ih.json.ResponseData;
import com.chixing.ih.module.programmer.pojo.dto.MyHomePageDTO;
import com.chixing.ih.module.programmer.pojo.dto.PGHomePageDTO;
import com.chixing.ih.module.programmer.pojo.dto.PieChaprtDTO;
import com.chixing.ih.module.programmer.pojo.dto.ProgrammerListDTO;
import com.chixing.ih.module.programmer.service.IHomePageService;
import com.chixing.ih.module.programmer.service.IProgrammerListService;
import com.chixing.ih.module.programmer.service.IProgrammerService;
import com.chixing.ih.module.task.pojo.DTO.OrderListDTO;
import com.chixing.ih.module.task.pojo.DTO.TaskShowDTO;
import com.chixing.ih.module.task.service.IOrderService;
import com.chixing.ih.module.task.service.ITaskService;
import com.chixing.ih.util.PageRequest;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @version 1.0
 * @Author MasterYan
 * @Date 2020/10/6
 * Time: 10:59
 */
@RestController
@RequestMapping("/homePage")
@Api(tags = "程序员模块查询首页相关Api")
public class HomePageController {

    @Autowired
    IHomePageService homePageService;

    @Autowired
    IOrderService orderService;

    @Autowired
    ITaskService taskService;

    @Autowired
    IProgrammerService programmerService;


    /**
     * desc:查询首页接口
     *
     * @param userId
     * @return
     */
    @ApiOperation(value = "查询首页接口", notes = "程序员查看自己的首页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户自己id", required = true, dataType = "long"),

    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
            @ApiResponse(code = 400, message = "查询失败"),
    })

    @GetMapping("/myHomePage/{userId}")
    public Map<String, Object> findMyHomePage(HttpServletRequest request, @PathVariable("userId") long userId) {
        MyHomePageDTO myHomePage = homePageService.findMyHomePage(request, userId);
        return ResponseData.REP_GET_SUCCESS(myHomePage);

    }

    /**
     * desc:查询其他程序员首页接口
     *
     * @param visitorId
     * @param visitedId
     * @return
     */
    @ApiOperation(value = "查询其他程序员首页接口", notes = "程序员查看其他程序员的首页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "visitorId", value = "查看人id", required = true, dataType = "long"),
            @ApiImplicitParam(name = "visitedId", value = "被查看人id", required = true, dataType = "long"),

    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })

    @GetMapping("/pGHomePage/{visitorId}/{visitedId}")
    public Map<String, Object> findPGHomePage(HttpServletRequest request, @PathVariable("visitorId") long visitorId, @PathVariable("visitedId") long visitedId) {
        PGHomePageDTO pgHomePage = homePageService.findPGHomePage(request, visitorId, visitedId);
        return ResponseData.REP_GET_SUCCESS(pgHomePage);

    }

    /**
     * desc:主页面饼图数据查询接口
     *
     * @return
     */
    @ApiOperation(value = "主页面饼图数据查询接口", notes = "网站主页饼图查询")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功")
    })

    @GetMapping("/pieChaprt")
    public Map<String, Object> findPieChaprt(HttpServletRequest request, PageRequest pageRequest) {
        long ordNum =orderService.orderTotalNumber();
        long taskNum = taskService.taskTotalNumber();
        long programmerNum = programmerService.listAllNum();
        PieChaprtDTO pieChaprtDTO = new PieChaprtDTO();
        pieChaprtDTO.setProgrammerNum(programmerNum);
        pieChaprtDTO.setTaskNum((long) taskNum);
        pieChaprtDTO.setOrdNum((long) ordNum);
        return ResponseData.REP_GET_SUCCESS(pieChaprtDTO);

    }


}
